package game.source.gui;

import game.source.manager.GameManager;
import game.source.manager.level.Level1;
import game.source.util.Timer;
import game.source.util.TimerControlInterface;
import game.source.util.TimerListener;

import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

public class GamePanel extends JPanel implements TimerListener,TimerControlInterface{
	private static final long serialVersionUID = 1310198761041869667L;
	private GameManager		manager;
	private Timer 			timer; 
	public GamePanel() {
		GuiComponent.setResolution(800, 600);
		this.timer			= new Timer(this,32);	//Atualiza automaticamente em 32 milisegundos (~30 fps)
		this.manager		= new Level1(this);
		this.timer.start();
	}
	@Override
	public void update(){
		this.repaint();
	}
	@Override
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		GuiComponent.setGraphics((Graphics2D)g);
		this.manager.show(this.timer.getDelta());
	}
	@Override
	public void start() {
		this.manager.start();
		this.timer.start();
	}
	@Override
	public void play() {
		this.manager.play();
		this.timer.play();

	}
	@Override
	public void pause() {
		this.manager.pause();
		this.timer.pause();
	}
	@Override
	public void end() {
		this.manager.end();
		this.timer.end();			
	}
	@Override
	public boolean isPaused() {
		return this.timer.isPaused();
	}
}
